<template>
<view class="search-main page-view">
	<view class="search-wrap">
		<image class="icon-search" src="@/static/images/icon/search.png"></image>
		<input class="search-input" v-model="searchContent" @input="onSearchInput"
		placeholder-class="search-input-placeholder" placeholder="日常 / 问题 / 症状 / 药品"/>
		<view class="clear-btn-wrap">
			<image src="@/static/images/icon/close.png" v-if="searchStatus != 0"
			@click="clearSearch"></image>
		</view>
		<view class="search-btn btn" @click="search">搜索</view>
	</view>
	
	<view class="search-before" v-if="searchStatus == 0">
		<view class="recommend-tag">
			<view class="wrap-title">推荐</view>
			<view class="list">
				<view class="item" v-for="item in tagList">
					{{ item.text }}
				</view>
			</view>
		</view>
		
		<view class="hot-discover" v-if="false">
			<view class="wrap-title">热门发现</view>
			<view class="list">
				<view class="item" v-for="item in hotDiscoverList">
					<text>{{ item.text }}</text>
					<image src="@/static/images/icon/fire.png"></image>
				</view>
			</view>
		</view>
		
		<view class="hot-search" v-else>
			<view class="wrap-title">热门搜索</view>
			<view class="list">
				<view class="item" v-for="(item, index) in hotSearchList" :key="index">
					<view class="rank" :style="{ background: styleBackground(index) }">{{ index + 1 }}</view>
					<view class="text">{{ item.text }}</view>
				</view>
			</view>
		</view>
	</view>
	
	<view class="searching" v-else-if="searchStatus == 1">
		<view class="item" v-for="item in 20">
			<view>狗狗 的寄生<text>虫</text>与<text>驱虫</text>方法</view>
			<image src="@/static/images/icon/put.png"></image>
		</view>
	</view>
	
	<view class="search-result" v-else-if="searchStatus == 2"
	@click="$router.to('article_detail', { parmas: {id: 1} })">
		<view class="item" v-for="item in 20">
			<image class="cover" src="@/static/images/a.jpg"></image>
			<view class="info">
				<view class="title">狗狗体外驱虫剂量-新手怎么玩?看完这篇就够了</view>
				<view class="tag-list">
					<view class="item">知识科普</view>
				</view>
			</view>
		</view>
	</view>
</view>
</template>

<script>
export default {
	data() {
		return {
			// 输入内容
			searchContent: "",
			// 搜索状态 0-未开始 1-输入中 2-搜索结束
			searchStatus: 0,
			// 推荐标签列表
			tagList: [
				{ text: "狗狗拉稀" },
				{ text: "狗狗拉稀" },
				{ text: "狗狗拉稀" },
				{ text: "狗狗拉稀" },
				{ text: "狗狗拉稀" },
				{ text: "狗狗拉稀" },
				{ text: "狗狗拉稀" }
			],
			// 热门发现列表
			hotDiscoverList: [
				{ text: "爪老师公益课堂" },
				{ text: "节育对爱宠们伤害大么" },
				{ text: "节育对爱宠们伤害大么" },
				{ text: "节育对爱宠们伤害大么" },
				{ text: "节育对爱宠们伤害大么" },
				{ text: "节育对爱宠们伤害大么" },
				{ text: "节育对爱宠们伤害大么" },
				{ text: "节育对爱宠们伤害大么" },
				{ text: "节育对爱宠们伤害大么" },
				{ text: "节育对爱宠们伤害大么" },
				{ text: "节育对爱宠们伤害大么" },
				{ text: "节育对爱宠们伤害大么" },
				{ text: "节育对爱宠们伤害大么" },
				{ text: "节育对爱宠们伤害大么" },
				{ text: "节育对爱宠们伤害大么" },
				{ text: "节育对爱宠们伤害大么" },
				{ text: "节育对爱宠们伤害大么" }
			],
			// 热门搜索列表
			hotSearchList: [
				{ text: "爪老师公益课堂" },
				{ text: "节育对爱宠们伤害大么" },
				{ text: "节育对爱宠们伤害大么" },
				{ text: "节育对爱宠们伤害大么" },
				{ text: "节育对爱宠们伤害大么" },
				{ text: "节育对爱宠们伤害大么" },
				{ text: "节育对爱宠们伤害大么" },
				{ text: "节育对爱宠们伤害大么" },
				{ text: "节育对爱宠们伤害大么" },
				{ text: "节育对爱宠们伤害大么" },
				{ text: "节育对爱宠们伤害大么" },
				{ text: "节育对爱宠们伤害大么" },
				{ text: "节育对爱宠们伤害大么" },
				{ text: "节育对爱宠们伤害大么" },
				{ text: "节育对爱宠们伤害大么" },
				{ text: "节育对爱宠们伤害大么" }
			]
		}
	},
	methods: {
		// 搜索
		search () {
			this.searchStatus = 2
		},
		// 清楚搜索
		clearSearch () {
			this.searchContent = ""
			this.searchStatus = 0
		},
		// 搜索输入监听
		onSearchInput (e) {
			let v = e.detail.value
			this.searchStatus = v.trim() ? 1 : 0
		},
		// 热门搜索排行背景颜色
		styleBackground (index) {
			switch (index) {
				case 0: return "#F44336";
				case 1: return "#FFAC32";
				case 2: return "#D4B490";
			}
		}
	}
}
</script>

<style lang="less">
.search-main {
	display: flex;
	flex-direction: column;
	padding: 20rpx 40rpx 0;
	
	.search-wrap {
		height: 84rpx;
		border-radius: 10rpx;
		display: flex;
		align-items: center;
		padding: 10rpx 12rpx 10rpx 24rpx;
		border: 1rpx solid #E2E2E2;
		box-shadow: 0rpx 4rpx 15rpx 0rpx rgba(187, 187, 187, 0.3);

		.icon-search {
			width: 28rpx;
			height: 28rpx;
		}
		
		.search-input {
			margin-left: 12rpx;
			font-size: 24rpx;
			flex: 1;
		}
		
		.search-input-placeholder {
			color: #C5C5C5;
		}
		
		.clear-btn-wrap {
			display: flex;
			align-items: center;
			justify-content: center;
			margin-left: 20rpx;
			width: 34rpx;
			height: 34rpx;
			
			>image {
				width: 100%;
				height: 100%;
			}
		}
		
		.search-btn {
			width: 88rpx;
			height: 63rpx;
			border-radius: 10rpx;
			background: #FF6D03;
			margin-left: 26rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			font-size: 24rpx;
			color: #FFFFFF;
		}
	}
	
	.wrap-title {
		font-size: 32rpx;
		font-weight: 600;
		line-height: 44rpx;
		letter-spacing: 0px;
		color: #0B1526;
	}
	
	.search-before {
		position: relative;
		width: 100vw;
		left: -40rpx;
		flex: 1;
		height: 0;
		overflow-y: auto;
		
		.recommend-tag {
			padding: 0 40rpx;
			margin-top: 34rpx;
			
			.list {
				margin-top: 28rpx;
				display: flex;
				flex-wrap: wrap;
				gap: 28rpx 20rpx;
				
				.item {
					display: flex;
					align-items: center;
					height: 48rpx;
					border-radius: 168rpx;
					padding: 0 24rpx;
					background: #E2F0FF;
					font-size: 24rpx;
					color: #0B1526;
				}
			}
		}
		
		.hot-discover {
			padding: 0 40rpx 40rpx;
			margin-top: 84rpx;
			
			.list {
				display: flex;
				flex-direction: column;
				align-items: flex-start;
				
				.item {
					display: flex;
					align-items: center;
					margin-top: 28rpx;
					gap: 6rpx;
					height: 48rpx;
					border-radius: 168rpx;
					padding: 0 24rpx;
					gap: 8px;
					background: #FFECCC;
					
					>text {
						font-size: 24rpx;
						color: #0B1526;
					}
					
					>image {
						width: 20rpx;
						height: 20rpx;
					}
				}
			}
		}
		
		.hot-search {
			position: relative;
			padding-bottom: 40rpx;
			margin-top: 50rpx;
			
			.wrap-title {
				display: flex;
				align-items: center;
				padding: 0 32rpx;
				height: 90rpx;
				border-radius: 24rpx 24rpx 0rpx 0rpx;
				background: linear-gradient(180deg,  rgba(250, 130, 31, 0.1011) 9%, rgba(249, 181, 63, 0.0001) 79%);
			}
			
			.list {
				margin-top: 36rpx;
				padding: 0 32rpx;
				
				.item {
					display: flex;
					align-items: center;
					gap: 20rpx;
					
					&:nth-child(n+2) {
						margin-top: 45rpx;
					}
					
					.rank {
						display: flex;
						align-items: center;
						justify-content: center;
						width: 36rpx;
						height: 36rpx;
						border-radius: 8rpx;
						background: #D0D3DE;
						font-size: 20rpx;
						font-weight: 500;
						color: #FFFFFF;
					}
					
					.text {
						font-size: 28rpx;
						color: #0B1526;
					}
				}
			}
		}
	}
	
	.searching {
		flex: 1;
		overflow-y: auto;
		
		.item {
			display: flex;
			align-items: center;
			justify-content: space-between;
			height: 104rpx;
			border-bottom: 1rpx solid #EBEBEB;
			
			>view {
				font-size: 24rpx;
				color: #000000;
				
				>text {
					color: #FF6D03;
				}
			}
			
			>image {
				width: 43rpx;
				height: 43rpx;
			}
		}
	}
	
	.search-result {
		flex: 1;
		overflow-y: auto;
		
		.item {
			display: flex;
			margin-top: 34rpx;
			gap: 30rpx;
			
			.cover {
				width: 192rpx;
				height: 192rpx;
				border-radius: 10rpx;
			}
			
			.info {
				flex: 1;
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				
				.title {
					font-size: 30rpx;
					line-height: 40rpx;
					color: #333333;
				}
				
				.tag-list {
					display: flex;
					flex-wrap: wrap;
					gap: 30rpx;
					
					.item {
						height: 48rpx;
						border-radius: 168rpx;
						display: flex;
						align-items: center;
						padding: 0 24rpx;
						background: #FFE7D6;
						font-size: 24rpx;
						color: #0B1526;
					}
				}
			}
		}
	}
}
</style>
